package client;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;

import service.IService;

public class SubCaseTest extends AbstractTest implements IService {

	   public static void main(String args[]) throws Exception {
	        
	    	testRequestJsonGetSubCases();
	    	//testRequestJsonPutSubCase();
	    	//testRequestJsonGetSubCase();
	    	//testRequestJsonTestRun();
	    	
	        System.out.println("\n"); 
	        System.exit(0);
	    }
	    private static void testRequestJsonGetSubCase()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP GET request to get single sub case info, expect JSON");
	        GetMethod get = new GetMethod(getTestHost()+ACTION_SUBCASE+"/1");
	        get.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();
	       
	        try {
	            int result = httpclient.executeMethod(get); 
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(get.getResponseBodyAsString());
	        } finally {
	            get.releaseConnection();             
	        }
	    }
	    private static void testRequestJsonGetSubCases()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP GET request to get sub cases info, expect JSON");
	        GetMethod get = new GetMethod(getTestHost()+ACTION_SUBCASES+"/1");
	        get.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();
	       
	        try {
	            int result = httpclient.executeMethod(get); 
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(get.getResponseBodyAsString());
	        } finally {
	            get.releaseConnection();             
	        }
	    }
	    
	  
	    
	    private static void testRequestJsonPutSubCase()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to put sub case info, use JSON, expect RESPONSE");
	        PostMethod post = new PostMethod(getTestHost()+ACTION_SAVESUBCASE);
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	        	
	        	post.setRequestEntity(new StringRequestEntity(" {\"SubCase\":[{\"id\":0,\"name\":\"SubCASE1\",\"type\":1,\"caseId\":1}]}"));

	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }
	    @SuppressWarnings("unused")
	    private static void testRequestJsonRemoveSubCase()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to remove sub case info, use JSON, expect RESPONSE");
	        PostMethod post = new PostMethod(getTestHost()+ACTION_REMOVESUBCASE+"/102");
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }
	    
	    @SuppressWarnings("unused")
	    private static void testRequestJsonTestRun()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to run sub case, use JSON, expect RESPONSE");
	        PostMethod post = new PostMethod(getTestHost()+ACTION_TESTRUN+"/1");
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }
	    
/*	    @SuppressWarnings("unused")
	    private static void testRequestJsonRunCase()throws Exception{
	    	System.out.println("\n");
	        System.out.println("Sent HTTP POST request to run case info, use JSON, expect RESPONSE");
	        PostMethod post = new PostMethod(getTestHost()+ACTION_TESTRUN+"/1");
	        
	        //System.out.println(getTestHost()+ACTION_TESTSRUN+"/1");
	        
	        post.addRequestHeader("Accept" , "application/json");
	        HttpClient httpclient = new HttpClient();

	        try {
	        	
	            int result = httpclient.executeMethod(post);
	            
	            System.out.println("Response status code: " + result);
	            System.out.println("Response body: ");
	            System.out.println(post.getResponseBodyAsString());
	        } finally {
	            post.releaseConnection();            
	        }
	    }*/
	    
}
